package views;

import utils.AppUtils;
import utils.MessageUtils;
import utils.SessionUtils;
import views.components.Header;
import views.components.BarraMenu;
import views.interfaces.INovice;
import app.structure.Application;

import com.vaadin.annotations.Theme;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("Theme02")
/**
 * Clase que es utilitza en una Aplicacio 
 *
 */
public class AppView extends CustomComponent implements View, INovice {

	private final VerticalLayout root;
	private Header header;
	private BarraMenu mnuBar;
	private String currentAppName;
	private int secLevel;

	public AppView() {

		currentAppName = SessionUtils.getSessionCurrentApp();

		header = new Header(MessageUtils.getI18n(currentAppName));

		secLevel = SessionUtils.getSessionAppSecLevel();

		Application application = AppUtils.getApplicationManager().getApp(
				currentAppName);

		mnuBar = new BarraMenu(application.getMenuStructs(), secLevel);

		mnuBar.setSizeUndefined();
		mnuBar.setMargin(true);
		mnuBar.setSpacing(true);
		
		root = new VerticalLayout(header, mnuBar);
		root.setMargin(true);
		root.setSpacing(true);
		root.setComponentAlignment(mnuBar, Alignment.TOP_CENTER);
		setCompositionRoot(root);
	}

	@Override
	public void setNovice(boolean novice) {

	}

	@Override
	public void enter(ViewChangeEvent event) {

	}

}
